package com.ysm.freestyle.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.ysm.freestyle.model.Student


class UserViewModel : ViewModel() {
    var student = Student("ysm",18)
    //私有的
    private val _stu = MutableLiveData<Student>().apply {
        value = student
    }
    //对外暴露的, 不可更改Value 的LiveData 防止通过stu直接修改其值
    var stu : LiveData<Student> = _stu

    //更新，对外更新接口
    fun updateStu(name:String,age:Int){
        _stu.value = student.apply {
            this.name = name
            this.age = age
        }
    }
}